package com.ywu.service.standard.api;

import com.ywu.common.result.CommonResult;
import com.ywu.service.standard.dto.ServiceDto;
import com.ywu.service.standard.service.ServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ServiceApi
 * @Description TODO
 * @Author GroundDemo
 * @Date 2024/3/1 21:02
 * @Version 1.0
 **/
@RestController
@RequestMapping("/ywu/service")
public class ServiceApi {
    @Autowired
    private ServiceService service;

    @Value("${gitee.ssh.publicKey}")
    private String sshKey;

    /**
    * @Author GroundDemo
    * @Description 查询所有微服务信息
    * @Date 21:12 2024/3/1
    * @Param []
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/application.info")
    public CommonResult<Object> getAllApplication(@RequestBody ServiceDto serviceDto) {
        return service.getAllApplication(serviceDto);
    }

    /**
     * @Author GroundDemo
     * @Description 添加微服务
     * @Date 21:12 2024/3/1
     * @Param []
     * @return com.ywu.common.result.CommonResult<java.lang.Object>
     **/
    @PostMapping("/application.add.info")
    public CommonResult<Object> addApplication(@RequestBody ServiceDto serviceDto) {
        return service.addApplication(serviceDto);
    }

    /**
     * @Author GroundDemo
     * @Description 修改微服务
     * @Date 21:12 2024/3/1
     * @Param []
     * @return com.ywu.common.result.CommonResult<java.lang.Object>
     **/
    @PostMapping("/application.update.info")
    public CommonResult<Object> updateApplication(@RequestBody ServiceDto serviceDto) {
        return service.updateApplication(serviceDto);
    }

    /**
     * @Author GroundDemo
     * @Description 删除微服务
     * @Date 21:12 2024/3/1
     * @Param []
     * @return com.ywu.common.result.CommonResult<java.lang.Object>
     **/
    @PostMapping("/application.delete.info")
    public CommonResult<Object> deleteApplication(@RequestBody ServiceDto serviceDto) {
        return service.deleteApplication(serviceDto);
    }

    /**
     * @Author GroundDemo
     * @Description 微服务分页nacos注册中心信息
     * @Date 21:12 2024/3/1
     * @Param []
     * @return com.ywu.common.result.CommonResult<java.lang.Object>
     **/
    @PostMapping("/application.nacos.info")
    public CommonResult<Object> getNacosApplicationInfo(@RequestBody ServiceDto serviceDto) {
        return service.getNacosApplicationInfo(serviceDto);
    }

    /**
    * @Author GroundDemo
    * @Description gitee的ssh秘钥
    * @Date 9:40 2025/3/23
    * @Param []
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/service.gitee.ssh.key")
    public CommonResult<Object> getCommonSshPublicKey() {
        return CommonResult.success(sshKey);
    }
}
